package io.renren.modules.app.service.impl;

import com.zheok.testing.entity.BannerEntity;
import com.zheok.testing.entity.JournalismEntity;
import com.zheok.testing.entity.ShopEntity;
import io.renren.modules.app.service.BusinessService;
import io.renren.modules.app.service.ShopService;
import io.renren.modules.sys.entity.SysUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.*;

import com.zheok.testing.dao.BusinessDao;
import com.zheok.testing.entity.BusinessEntity;
import org.springframework.util.StringUtils;


@Service("businessService")
public class BusinessServiceImpl extends ServiceImpl<BusinessDao, BusinessEntity> implements BusinessService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {


        QueryWrapper<BusinessEntity> wrapper = new QueryWrapper<>();

        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        String username = userEntity.getUsername();
        if(!"admin".equals(username)){
            wrapper.lambda().eq(BusinessEntity::getShopId,userEntity.getUserId());
        }
        String key = (String) params.get("key");

        if(!StringUtils.isEmpty(key)){
            wrapper.lambda().like(BusinessEntity::getTitle,key);
        }
        IPage<BusinessEntity> page = this.page(
                new Query<BusinessEntity>().getPage(params),
             wrapper
        );

        return new PageUtils(page);
    }

    @Autowired
    private ShopService shopService;
    @Override
    public void saveinfo(BusinessEntity business) {
        SysUserEntity userEntity = ShiroUtils.getUserEntity();
        business.setShopId(userEntity.getUserId());
        business.setShopName(userEntity.getName());

        this.saveOrUpdate(business);
    }

}